home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / Identify.c < prev    next >
Text File  |  1995-03-26  |  12KB  |  404 lines

  1. /* Identify.c
  2. Each routine returns an informative C string. Here are samples. (I suggest you
  3. use BreakLines() to printf the longer ones.)
  4.  
  5. IdentifyCompiler:
  6. "THINK C 6 compiled to generate 68020 and 68881 instructions, 
  7. and use 12-byte universal-format doubles."
  8.  
  9. IdentifyOwner:
  10. "Denis Pelli"
  11.  
  12. IdentifyModel:
  13. "PowerBook 170"
  14.  
  15. IdentifyMachine:
  16. "Denis Pelli’s PowerBook 170 with 68030 and 68882 running System 7.10, ROM 1024K
  17. version 124+6*256. Caching data & instructions."
  18.  
  19. IdentifyVideo(device):
  20. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM) in slot 0"
  21.  
  22. The computer model appears only if the slot==0, which indicates built-in video. The
  23. curly quotes embrace the card name, and the parentheses embrace the driver name.
  24. The driver's version number appears only if it's non-zero.
  25.  
  26. HISTORY:
  27. 1/29/92    dgp wrote IdentifyCompiler.
  28. 2/25/92    dgp    wrote IdentifyMachine.
  29. 8/26/92    dgp get owner and model name from the System file
  30. 2/20/93    dgp    added ROM version
  31. 2/27/93    dgp merged IdentifyCompiler.c and IdentifyMachine.c into the new Identify.c,
  32.             and added IdentifyVideo.
  33. 4/25/93    dgp    IdentifyMachine reports 24/32-bit addressing.
  34. 12/14/93 dgp If THINK C compiler version is "5" I report "5 or 6.0" since Symantec
  35.             forgot to increment the version number when they released 6.0. They
  36.             fixed this in version 6.01.
  37. 3/2/94    dgp    Extracted IdentifyOwner from within IdentifyMachine
  38. 7/28/94 dgp added support for Metrowerks CodeWarrior C compiler and PowerPC.
  39.             Eliminated use of "#s" printf format, since it's not supported by
  40.             Metrowerks CodeWarrior C.
  41. 9/5/94 dgp     removed assumption in printf's that int==short.
  42. 9/6/94    dgp    Enhanced IdentifyCompiler to specify the size of int.
  43. 9/6/94    dgp    Disable cache checks on PowerPC, because those traps are undefined.
  44. 10/5/94 dgp Removed all floating point code from IdentifyCompiler().
  45. 11/5/94 dgp Suppressed ROM info in Identify.
  46. 11/9/94 dgp added IdentifyApplication().
  47. 1/15/94 dgp added test for version 5 of CodeWarrior
  48. */
  49. #include "VideoToolbox.h"
  50. #include <Traps.h>    // _HWPriv
  51. #include "mc68881.h"
  52. #if UNIVERSAL_HEADERS
  53.     #include <LowMem.h>
  54. #else
  55.     #define LMGetCurApName() ((StringPtr) 0x0910)
  56.     #define gestaltNativeCPUtype 'cput'
  57.     enum{
  58.         gestaltCPU601                = 0x101,
  59.         gestaltCPU603                = 0x103,
  60.         gestaltCPU604                = 0x104
  61.     };
  62. #endif
  63.  
  64. #undef __CW__
  65. #define __CW__ 4
  66. #if defined(__fourbyteints__)    // this symbol first appeared in version 5.0
  67.     #undef __CW__
  68.     #define __CW__ 5
  69.     #if !defined(powerc)
  70.         #if __option(IEEEdoubles) == __ieeedoubles__  // false in CW 5.0 68k compiler
  71.             #undef __CW__
  72.             #define __CW__ 5.5
  73.         #endif
  74.         #pragma fourbyteints off
  75.         // Surprisingly, the CW5.5 68k compiler fails this test ONLY if run on the PowerPC.
  76.         #if __option(fourbyteints) == __fourbyteints__ // false in CW 5.0 and 5.5 68k compilers
  77.             #undef __CW__
  78.             #define __CW__ 6
  79.         #endif
  80.         #pragma fourbyteints reset
  81.     #else
  82.         // Can anyone devise a test to distinguish version 5.5 from 5 of the ppc compiler?
  83.     #endif
  84. #endif
  85.  
  86. /*
  87. This table was complete in summer '92, but does not include the newer models.
  88. However, the table is used only as a backup, when the System lacks a machine name
  89. string, which is a feature of System 7. Since all new machines nominally require
  90. System 7, it is unlikely that it will ever be necessary to look them up in
  91. this table.
  92. */
  93. char machineName[][20]={
  94.     "Unknown Mac","Mac 128K","Mac XL","Mac 512KE","Mac Plus","Mac SE","Mac II"
  95.     ,"Mac IIx","Mac IIcx","Mac SE/30","Mac Portable","Mac IIci","Unknown Mac"
  96.     ,"Mac IIfx","Unknown Mac","Unknown Mac","Unknown Mac"
  97.     ,"Mac Classic","Mac IIsi","Mac LC","Mac Quadra 900","PowerBook 170"
  98.     ,"Mac Quadra 700","Mac Classic II","PowerBook 100","PowerBook 140","Quadra 950"
  99.     ,"Unknown Mac"
  100. // Despite the above, it appears that System 7.5 took a step backwards and lacks
  101. // specific names for many machines, so I've used Gestalt Selectors List 2.8 (March '95)
  102. // to update the list to include all currently available Macs.
  103. // However, the Metrowerks CodeWarrior C 5.5 compiler complains that I've got
  104. // too many initializers, so I'm leaving this addition commented out for the time being.
  105. /*
  106.     ,"Mac LC III"
  107.     ,"Unknown Mac"
  108.     ,"Mac PowerBook 210"
  109.     ,"Mac Centris 650"
  110.     ,"Unknown Mac"
  111.     ,"Mac PowerBook 230"
  112.     ,"Mac PowerBook 180"
  113.     ,"Mac PowerBook 160"
  114.     ,"Mac Quadra 800"
  115.     ,"Mac Quadra 650"
  116.     ,"Mac LC II"
  117.     ,"Mac PowerBook Duo 250"
  118.     ,"Power Mac 9150"
  119.     ,"Power Mac 8100/110"
  120.     ,"Unknown Mac"
  121.     ,"Unknown Mac"
  122.     ,"Unknown Mac"
  123.     ,"Mac IIvi"
  124.     ,"Mac Performa 600"
  125.     ,"Unknown Mac"
  126.     ,"Power Mac 7100/80"
  127.     ,"Mac IIvx"
  128.     ,"Mac Color Classic"
  129.     ,"Mac PowerBook 165c"
  130.     ,"Unknown Mac"
  131.     ,"Mac Centris 610"
  132.     ,"Mac Quadra 610"
  133.     ,"Mac PowerBook 145,145b"
  134.     ,"Power Mac 8100/100"
  135.     ,"Mac LC 520"
  136.     ,"Unknown Mac"
  137.     ,"Unknown Mac"
  138.     ,"Unknown Mac"
  139.     ,"Mac Centris 660AV"
  140.     ,"Unknown Mac"
  141.     ,"Mac Performa 460"
  142.     ,"Unknown Mac"
  143.     ,"Unknown Mac"
  144.     ,"Power Mac 8100/80"
  145.     ,"Unknown Mac"
  146.     ,"Unknown Mac"
  147.     ,"Unknown Mac"
  148.     ,"Unknown Mac"
  149.     ,"Unknown Mac"
  150.     ,"Mac PowerBook 180c"
  151.     ,"Mac PowerBook 520,520c,540,540c"
  152.     ,"Unknown Mac"
  153.     ,"Unknown Mac"
  154.     ,"Power Mac 6100/60"
  155.     ,"Unknown Mac"
  156.     ,"Mac PowerBook Duo 270c"
  157.     ,"Mac Quadra 840AV"
  158.     ,"Unknown Mac"
  159.     ,"Mac LC 550/Performa550"
  160.     ,"Unknown Mac"
  161.     ,"Unknown Mac"
  162.     ,"Unknown Mac"
  163.     ,"Mac PowerBook 165"
  164.     ,"Unknown Mac"
  165.     ,"Unknown Mac"
  166.     ,"Unknown Mac"
  167.     ,"Mac TV"
  168.     ,"Mac LC 475/Performa47x"
  169.     ,"Unknown Mac"
  170.     ,"Unknown Mac"
  171.     ,"Mac LC 575"
  172.     ,"Unknown Mac"
  173.     ,"Mac Quadra 605"
  174.     ,"Unknown Mac"
  175.     ,"Unknown Mac"
  176.     ,"Unknown Mac"
  177.     ,"Mac LC 630/Quadra 630"
  178.     ,"Unknown Mac"
  179.     ,"Power Mac 6100/66"
  180.     ,"Unknown Mac"
  181.     ,"Mac PowerBook Duo 280"
  182.     ,"Mac PowerBook Duo 280c"
  183.     ,"Unknown Mac"
  184.     ,"Unknown Mac"
  185.     ,"Unknown Mac"
  186.     ,"Unknown Mac"
  187.     ,"Unknown Mac"
  188.     ,"Unknown Mac"
  189.     ,"Unknown Mac"
  190.     ,"Unknown Mac"
  191.     ,"Power Mac 7100/66"
  192.     ,"Unknown Mac"
  193.     ,"Unknown Mac"
  194.     ,"Mac PowerBook 150"
  195.     ,"Power Macintosh 700 (Q700 upgr)"
  196.     ,"Power Macintosh 900 (Q900 upgr)"
  197.     ,"Power Macintosh 950 (Q950 upgr)"
  198.     ,"Power Macintosh C610 (C610 upgr)"
  199.     ,"Power Macintosh C650 (C650 upgr)"
  200.     ,"Power Macintosh Q610 (Q610 upgr)"
  201.     ,"Power Macintosh Q650 (Q650 upgr)"
  202.     ,"Power Macintosh 800 (Q800 upgr)"
  203. */
  204. };
  205.  
  206. char fpuName[][32]={
  207.     "no floating point unit","68881","68882","built-in floating point"
  208.     ,"unknown floating point unit","Software FPU"
  209. };
  210.  
  211. char *IdentifyCompiler(void)
  212. {
  213.     static char string[200];
  214.     char *compiler,*longs,*floating,version[4],*universal;
  215.     double v=0;
  216.     
  217.     string[0]=0;
  218.     compiler="";
  219.     #if THINK_C
  220.         compiler="Symantec THINK C";
  221.         if(THINK_C==1)v=4;
  222.         else v=THINK_C;
  223.     #endif
  224.     #if THINK_CPLUS
  225.         compiler="Symantec C++";
  226.         v=THINK_CPLUS;
  227.     #endif
  228.     #if applec
  229.         compiler="MPW C";
  230.     #endif
  231.     #if __MWERKS__
  232.         compiler="Metrowerks CodeWarrior C";
  233.         if(!iscntrl(0))v=4;    // bug in version 4.5 and earlier
  234.         else v=5;
  235.         // v=__CW__;
  236.     #endif
  237.     if(v>0)sprintf(version,"%.0f ",v);
  238.     else sprintf(version,"");
  239.     if(mc68020)longs="68020";
  240.     else{
  241.         #if __powerc
  242.             longs="PowerPC";
  243.         #else
  244.             longs="68000";
  245.         #endif
  246.     }
  247.     if(mc68881)floating=" and 68881";
  248.     else floating="";
  249.     universal="";
  250.     if(sizeof(double)==12){
  251.         #if defined(THINK_C)
  252.             #if !__option(native_fp)
  253.                 universal="\"universal\"-format ";
  254.             #endif
  255.         #endif
  256.     }
  257.     sprintf(string,"Compiled by %s %sfor %s%s, using %ld-byte int and %s%ld-byte double."
  258.         ,compiler,version,longs,floating,sizeof(int),universal,sizeof(double));
  259.     return string;
  260. }
  261.  
  262. char *IdentifyModel(void)
  263. {
  264.     int error;
  265.     long machine;
  266.     int machines=sizeof(machineName)/sizeof(machineName[0]);
  267.     static char string[32];
  268.  
  269.     string[0]=0;
  270.     error=Gestalt(gestaltMachineType,&machine);
  271.     if(!error){
  272.         GetIndString((unsigned char *)string,kMachineNameStrID,machine);
  273.         p2cstr((unsigned char *)string);
  274.         if(strlen(string)==0){
  275.             if(machine<0 || machine>=machines)machine=0;
  276.             sprintf(string,"%s",machineName[machine]);
  277.         }
  278.     }
  279.     return string;
  280. }
  281.  
  282. char *IdentifyVideo(GDHandle device)
  283. // E.g. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM)"
  284. {
  285.     static char string[256];
  286.     long quickDraw;
  287.  
  288.     string[0]=0;
  289.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  290.     if(quickDraw<gestalt8BitQD){
  291.         sprintf(string,"%s ",IdentifyModel());
  292.         sprintf(string,"%s“%s”",string,"1-bit QuickDraw");
  293.     }else{
  294.         if(GetDeviceSlot(device)==0)sprintf(string,"%s ",IdentifyModel());
  295.         sprintf(string,"%s“%s”",string,GDCardName(device));
  296.         if(GDVersion(device)==0)sprintf(string,"%s (%s)",string,GDNameStr(device));
  297.         else sprintf(string,"%s (%s version %d)"
  298.             ,string,GDNameStr(device),(int)GDVersion(device));
  299.         sprintf(string,"%s slot %d",string,(int)GetDeviceSlot(device));
  300.     }
  301.     return string;
  302. }
  303.  
  304. char *IdentifyOwner(void)
  305. {
  306.     static char string[64];
  307.     unsigned char **owner;
  308.     
  309.     string[0]=0;
  310.     owner=GetString(-16096);    // Get owner's name from System file
  311.     if(owner!=NULL && *owner[0]>0){
  312.         memcpy(string,*owner,(*owner)[0]+1);
  313.         p2cstr((unsigned char *)string);
  314.     }
  315.     return string;
  316. }
  317.  
  318. char *IdentifyApplication(void)    // Returns name of application.
  319. {
  320.     static char string[32];
  321.  
  322.     memcpy(string,LMGetCurApName(),32);
  323.     p2cstr((unsigned char *)string);
  324.     return string;
  325. }
  326.  
  327. char *IdentifyMachine(void)
  328. {
  329.     int error;
  330.     long fpu,processor,system,value;
  331.     int fpus=sizeof(fpuName)/sizeof(fpuName[0]);
  332.     static char string[256];
  333.     Boolean cacheData=1,cacheInstructions=1;
  334.     long romSize,romVersion,qD;
  335.     char *processorName,*owner;
  336.     
  337.     string[0]=0;
  338.     error=Gestalt(gestaltSystemVersion,&system);
  339.     if(error)return string;                        /* Gestalt not available */
  340.     error=Gestalt(gestaltNativeCPUtype,&processor);
  341.     if(error)Gestalt(gestaltProcessorType,&processor);
  342.     Gestalt(gestaltFPUType,&fpu);
  343.     if(fpu<0 || fpu>=fpus)fpu=fpus-2;
  344.     if(fpu==1 && Gestalt('FPUE',&value)==0)fpu=fpus-1;// Software FPU by John Neil & Assoc.
  345.     owner=IdentifyOwner();
  346.     if(strlen(owner)>0)sprintf(string,"%s’s ",owner);
  347.     sprintf(string,"%s%s",string,IdentifyModel());
  348.     switch(processor){
  349.         case 1: processorName="68000";break;
  350.         case 2: processorName="68010";break;
  351.         case 3: processorName="68020";break;
  352.         case 4: processorName="68030";break;
  353.         case 5: processorName="68040";break;
  354.         case gestaltCPU601: processorName="PPC601";break;
  355.         case gestaltCPU603: processorName="PPC603";break;
  356.         case gestaltCPU604: processorName="PPC604";break;
  357.         default: processorName="unknown processor";break;
  358.     }
  359.     sprintf(string,"%s with %s and %s running System %lx.%lx"
  360.         ,string,processorName,fpuName[fpu],system/0x100,system%0x100/0x10);
  361.     system%=0x10;
  362.     if(system)sprintf(string,"%s.%lx",string,system);
  363.     sprintf(string,"%s.",string);
  364.     Gestalt(gestaltROMSize,&romSize);
  365.     Gestalt(gestaltROMVersion,&romVersion);
  366.     // I've never found any use for the ROM info, so I'm suppressing it.
  367.     if(0)sprintf(string,"%s, %ldK ROM version %ld+%ld*256."
  368.         ,string,romSize/1024,romVersion%256,romVersion/256);
  369.     if(TrapAvailable(_HWPriv)){
  370.         #if !__powerc    /* apparently these functions don't work on PowerPC */
  371.             cacheData=SwapDataCache(1);
  372.             SwapDataCache(cacheData);
  373.             cacheInstructions=SwapInstructionCache(1);
  374.             SwapInstructionCache(cacheInstructions);
  375.             if(cacheData || cacheInstructions)sprintf(string,"%s Caching",string);
  376.             else sprintf(string,"%s No caching",string);
  377.             if(cacheData)sprintf(string,"%s data",string);
  378.             if(cacheData && cacheInstructions)sprintf(string,"%s &",string);
  379.             if(cacheInstructions)sprintf(string,"%s instructions",string);
  380.             sprintf(string,"%s.",string);
  381.         #endif
  382.     }
  383.     value=0;
  384.     Gestalt(gestaltAddressingModeAttr,&value);
  385.     if(value&1<<gestalt32BitAddressing)sprintf(string,"%s 32-bit addressing.",string);
  386.     else sprintf(string,"%s 24-bit addressing.",string);
  387.     Gestalt(gestaltQuickdrawVersion,&qD);
  388.     switch(qD/0x100){
  389.         case 0:
  390.             sprintf(string,"%s 1-bit QuickDraw.",string);
  391.             break;
  392.         case 1:
  393.             sprintf(string,"%s 8-bit QuickDraw.",string);
  394.             break;
  395.         case 2:
  396.             sprintf(string,"%s 32-bit QuickDraw 1.%02lx.",string,qD%0x100);
  397.             break;
  398.         default:
  399.             sprintf(string,"%s QuickDraw 0x%lx.",string,qD);
  400.             break;
  401.     }
  402.     return string;
  403. }
  404.